package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.PageInfo;
import com.yyb.dto.*;
import com.yyb.enums.BusinessType;
import com.yyb.service.TbDormService;
import com.yyb.vo.TbDormVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "宿舍管理接口")
@RestController
@RequestMapping("/api/dorm")
@RequiredArgsConstructor
public class TbDormController {

    private final TbDormService dormService;
    /** 条件分页查询 */
    @Operation(summary = "分页查询宿舍列表")
    @PostMapping("/page")
    @AppPermission("system:dorm:query")
    public PageInfo<TbDormVO, TbDormQueryDTO> list(@RequestBody TbDormQueryDTO dto) {
        return dormService.listDormPage(dto);
    }
    /** 新增 */
    @Operation(summary = "新增宿舍")
    @PostMapping
    @AppPermission("system:dorm:add")
    @Log(title = "宿舍管理-新增", businessType = BusinessType.INSERT)
    public TbDormVO add(@RequestBody @Valid TbDormAddDTO dto) {
        return dormService.addDorm(dto);
    }

    /** 修改 */
    @Operation(summary = "修改宿舍")
    @PutMapping
    @AppPermission("system:dorm:update")
    @Log(title = "宿舍管理-修改", businessType = BusinessType.UPDATE)
    public TbDormVO update(@RequestBody @Valid TbDormUpdateDTO dto) {
        return dormService.updateDorm(dto);
    }

    /** 删除（单条） */
    @Operation(summary = "删除宿舍")
    @DeleteMapping("/{id}")
    @AppPermission("system:dorm:remove")
    @Log(title = "宿舍管理-删除", businessType = BusinessType.DELETE)
    public void delete(@PathVariable Long id) {
        dormService.deleteDorm(id);
    }

    /** 批量删除 */
    @Operation(summary = "批量删除宿舍")
    @DeleteMapping
    @AppPermission("system:dorm:remove")
    @Log(title = "宿舍管理-批量删除", businessType = BusinessType.DELETE)
    public void deleteBatch(@RequestBody List<Long> ids) {
        dormService.deleteDormBatch(ids);
    }

    /** 查询详情 */
    @Operation(summary = "查询宿舍详情")
    @GetMapping("/{id}")
    @AppPermission("system:dorm:query")
    public TbDormVO detail(@PathVariable Long id) {
        return dormService.getDorm(id);
    }


}
